package com.example.runningdemo.designModel.prototype;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * @program: Running-Demo
 * @description:
 * @author: kangwei
 * @create: 2024-08-12 09:37
 **/
@Setter
@Getter
public class User implements Cloneable {

    private String userName;
    private String userPwd;
    private List<String> phones;


    @Override
    protected Object clone() throws CloneNotSupportedException {
        User user = (User) super.clone();
        // user.phones = (List<String>) this.phones.clone(); // 深拷贝 todo 编译不过
        return user;
    }

    public static void main(String[] args) {
        User user = new User();
        user.setUserName("测试");
        user.setUserPwd("222");
        System.out.println(user);
        try {
            User clone = (User) user.clone();
            System.out.println(clone);
            System.out.println(user == clone); // false
        } catch (CloneNotSupportedException e) {
        }
    }
}
